package mk.timska_rabota_android.contacts;

import java.util.ArrayList;
import java.util.Iterator;

import mk.timska_rabota_android.SendMessage;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;

public class ContactsModule {
	public static String uid = "mk.timska_rabota_android.userId";
	public static String token = "mk.timska_rabota_android.token";
	public static String email = "mk.timska_rabota_android.email";
	
	public static ArrayList<String> contactsToStrings(ArrayList<Contact> ContactList){
		ArrayList<String> retValue = new ArrayList<String>();
		Iterator<Contact> iter = ContactList.iterator();
		while(iter.hasNext()){
			retValue.add(iter.next().toString());
		}
		
		return retValue;
	}
	
	public static void setMyUser(Context Con, Activity Act, Contact Me){  //should save session data, dummy for now
		final SharedPreferences sharedPref = getSharedPreferences(Con, Act);
		int appVersion = getAppVersion(Con);
		SharedPreferences.Editor editor = sharedPref.edit();
		editor.putString(uid, Me.getID()); //
		editor.putString(email, Me.getEmail());
		editor.putString(token, "");
		editor.commit();
	}
	
	private static int getAppVersion(Context context) {
	    try {
	        PackageInfo packageInfo = context.getPackageManager()
	                .getPackageInfo(context.getPackageName(), 0);
	        return packageInfo.versionCode;
	    } catch (NameNotFoundException e) {
	        throw new RuntimeException("Could not get package name: " + e);
	    }
	}
	
	public static SharedPreferences getSharedPreferences(Context con, Activity act){
		return act.getSharedPreferences(SendMessage.class.getSimpleName(), Context.MODE_PRIVATE);
	}
	
	public static ArrayList<Contact> getMyContacts(){
		ArrayList<Contact> retVal = new ArrayList<Contact>();
		
		/* To-Do
		 * Vrakanje na moi kontakti, dali bi bilo toa od baza ili extrakcija od kontakti
		 * */
		
		retVal.add(new Contact("1","Pero","+38972207102","pero@example.com")); //Dummy kontakti, cisto za proba, 
		retVal.add(new Contact("2","Kiro","+7777777777","kiro@example.com"));  //ne treba da stojat vo krajna verzija
		retVal.add(new Contact("3","Kiro","+7777777777","kiro@example.com"));
		retVal.add(new Contact("4","Kiro","+7777777777","kiro@example.com"));
		retVal.add(new Contact("5","Kiro","+7777777777","kiro@example.com"));
		retVal.add(new Contact("6","Kiro","+7777777777","kiro@example.com"));
		retVal.add(new Contact("7","Kiro","+7777777777","kiro@example.com"));
		retVal.add(new Contact("8","Kiro","+7777777777","kiro@example.com"));
		retVal.add(new Contact("9","Kiro","+7777777777","kiro@example.com"));
		retVal.add(new Contact("10","Kiro","+7777777777","kiro@example.com"));
		
		return retVal;
	}
}
